<template>
  <div class="app-container">
    <div class="top-banner">
      <card title="库存统计">
        <template v-slot:content>
          <div class="top-content">
            <div class="svg-box">
              <svg-icon class="svg_icon" icon-class="OutboundRP" />
              <div class="right-item">
                <div class="svg-num1">{{ EntryTotal?EntryTotal:0 }}</div>
                <div class="svg-name">入库记录</div>
              </div>
            </div>
            <div class="svg-box">
              <svg-icon class="svg_icon" icon-class="InventoryNum" />
              <div class="right-item">
                <div class="svg-num1">{{ EntrySum?EntrySum:0 }}</div>
                <div class="svg-name">入库数量</div>
              </div>
            </div>
            <div class="svg-box">
              <svg-icon class="svg_icon" icon-class="StorageRP" />
              <div class="right-item">
                <div class="svg-num2">{{ UseTotal?UseTotal:0 }}</div>
                <div class="svg-name">出库记录</div>
              </div>
            </div>
            <div class="svg-box">
              <svg-icon class="svg_icon" icon-class="OutboundNum" />
              <div class="right-item">
                <div class="svg-num2">{{ UseSum?UseSum:0 }}</div>
                <div class="svg-name">出库数量</div>
              </div>
            </div>
          </div>
        </template>
      </card>
    </div>
    <div class="container">
      <card title="库存管理">
        <template v-slot:content>
          <div class="content">
            <el-form
              :model="queryParams"
              ref="queryForm"
              size="small"
              :inline="true"
            >
              <el-form-item label="资产类型">
                <el-select v-model="queryParams.assetType" placeholder="请选择资产类型" clearable>
                  <el-option
                    v-for="item in dict.type.asset_type"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="物品名称">
                <el-input
                  v-model="queryParams.productName"
                  placeholder="请输入物品名称"
                  clearable
                  style="width: 240px"
                />
              </el-form-item>
              <el-form-item>
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  size="mini"
                  @click="getAdminAssetList"
                >搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
            <el-table
              v-loading="loading"
              :data="InventoryList"
              @selection-change="handleSelectionChange"
            >
              <el-table-column type="selection" width="50" align="center" />

              <el-table-column type="index" width="50" />
              <el-table-column label="资产类型" align="center" prop="assetType" sortable>
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.asset_type" :value="scope.row.assetType" />
                </template>
              </el-table-column>
              <el-table-column
                label="资产编码"
                align="center"
                key="assetCode"
                prop="assetCode"
                :show-overflow-tooltip="true"
              />
              <el-table-column
                label="物品名称"
                align="center"
                key="productName"
                prop="productName"
                :show-overflow-tooltip="true"
              />
              <el-table-column label="入库数量" align="center" key="inputNum" prop="inputNum" />
              <el-table-column label="领用数量" align="center" key="useNum" prop="useNum" />
              <el-table-column label="剩余数量" align="center" key="leaveCount" prop="leaveCount" />
              <el-table-column label="备注" align="center" key="remarks" prop="remarks" />
              <el-table-column
                label="操作"
                align="center"
                width="160"
                class-name="small-padding fixed-width"
              >
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-s-order"
                    @click="handleReport(scope.row)"
                  >出入库记录</el-button>
                </template>
              </el-table-column>
            </el-table>

            <pagination
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize"
              @pagination="getAdminAssetList"
            />
          </div>
        </template>
      </card>
    </div>
    <el-dialog title="出入库记录" :visible.sync="show" width="80%" append-to-body>
      <el-form :model="form" ref="form" size="small" :inline="true" >
        <el-form-item label="登记时间">
          <el-date-picker
            v-model="datetimerange"
            type="datetimerange"
            range-separator="至"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            start-placeholder="开始日期"
            size="small"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>

        <el-form-item label="物品名称">
          <el-input
            v-model="form.productName"
            placeholder="请输入物品名称"
            clearable
            style="width: 240px"
          />
        </el-form-item>
        <el-form-item label="办理人">
          <el-input v-model="form.transactor" placeholder="请输入办理人" clearable style="width: 240px" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getAssetHistory">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery1">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="tableList">
        <el-table-column type="selection" width="50" align="center" />

        <el-table-column type="index" width="50" />
        <el-table-column label="登记时间" align="center" prop="entryDate" sortable />

        <el-table-column
          label="资产编码"
          align="center"
          key="assetCode"
          prop="assetCode"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="物品名称"
          align="center"
          key="productName"
          prop="productName"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="入库数量" align="center" key="inputNum" prop="inputNum" />
        <el-table-column label="领用数量" align="center" key="useNum" prop="useNum" />
        <el-table-column label="办理人" align="center" prop="transactor" sortable />
      </el-table>

      <pagination
        v-show="total1>0"
        :total="total1"
        :page.sync="form.pageNum"
        :limit.sync="form.pageSize"
        @pagination="getAssetHistory"
      />
    </el-dialog>
  </div>
</template>

<script>
import {
  getAssetHistory,
  getAdminAssetList,
  getAllHasFinishUse,
  getAllHasFinishEntry
} from "@/api/oa/adminAsset";
import card from "@/views/homePage/components/card";
export default {
  data() {
    return {
      EntryTotal: null,
      EntrySum: null,
      UseTotal: null,
      UseSum: null,
      datetimerange: null,
      InventoryList: [
        {
          assetType: "办公用品",
          productName: "A4笔记本",
          assetCode: "B2023021401",
          inputNum: 50,
          useNum: 10,
          leaveCount: 40,
          remarks: undefined
        }
      ],
      show: false,
      tableList: [],

      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      total: 2,
      form: {
        pageNum: 1,
        pageSize: 10
      },
      total1: 2
    };
  },
  dicts: ["asset_type"],
  components: {
    card
  },
  mounted() {
    this.getAllHasFinishUse();
    this.getAllHasFinishEntry();
    this.getAdminAssetList();
  },
  methods: {
    getAllHasFinishUse() {
      getAllHasFinishUse().then(res => {
        this.UseTotal = res.data.total;
        this.UseSum = res.data.sum;
      });
    },
    getAllHasFinishEntry() {
      getAllHasFinishEntry().then(res => {
        this.EntryTotal = res.data.total;
        this.EntrySum = res.data.sum;
      });
    },
    getAssetHistory() {
      if (this.datetimerange) {
        this.form.startDate = this.datetimerange[0];
        this.form.endDate = this.datetimerange[1];
      } else {
        this.form.startDate = null;
        this.form.endDate = null;
      }
      getAssetHistory(this.form).then(res => {
        this.tableList = res.rows;
        this.total1 = res.total;
      });
    },
    getAdminAssetList() {
      getAdminAssetList(this.queryParams).then(res => {
        this.InventoryList = res.rows;
        this.total = res.total;
      });
    },
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10
      };
      this.getAdminAssetList();
    },
    resetQuery1() {
      this.form = {
        pageNum: 1,
        pageSize: 10
      };
      this.datetimerange = null;
      this.getAssetHistory();
    },
    handleSelectionChange() {},
    handleReport(item) {
      this.form.productName = item.productName;
      this.getAssetHistory();
      this.show = true;
    }
  }
};
</script>

<style lang="scss" scoped>
.app-container {
  width: 100%;
  height: 100%;
  padding: 0.125rem;
  overflow: hidden;
  background: #edefef;
  letter-spacing: 0.02rem;
  .top-banner {
    width: 100%;
    height: 1.875rem;
    background: #ffffff;
    margin-bottom: 0.125rem;
  }
  .container {
    width: 100%;
    height: calc(100% - 2rem);
    background: #ffffff;
    margin-bottom: 0.125rem;
  }
}
.top-content {
  width: 100%;
  display: flex;
  justify-content: space-around;
  align-items: center;
  .svg-box {
    display: flex;
    align-items: center;
    .svg_icon {
      height: 0.625rem;
      width: 0.625rem;
      margin-right: 0.125rem;
    }
    .right-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      .svg-num1 {
        color: #ffc600;
        font-size: 0.325rem;
      }
      .svg-num2 {
        color: #043eb8;
        font-size: 0.325rem;
      }
      .svg-name {
        font-size: 0.2rem;
        font-weight: 600;
      }
    }
  }
}
</style>
